<?php
class LotusGradeModel
{
	private $tableName = 'e_lotus_grade';
	
	
	public function addInfo($info){
		$model = new E_lotus_grade();
        $sql = "insert into $this->tableName (";
        foreach ($model as $key => $value) {
            if (isset($info->$key)) {
                $sql .= "$key,";
            }
        }
        $sql = substr($sql, 0, - 1);
        $sql .= ") values (";
        foreach ($model as $key => $value) {
            if (isset($info->$key)) {
                $sql .= "'" . addslashes($info->$key) . "',";
            }
        }
        $sql = substr($sql, 0, - 1);
        $sql .= ");";
        mysql_query($sql);
        return mysql_insert_id();
	}
	public function getByGradeId($gradeId)
	{
		$sql = "select * from $this->tableName where GradeId=$gradeId limit 0,1";
		$result = mysql_query ( $sql );
		return mysql_fetch_object ( $result );
	}
	public function setInfoById($info, $gradeId)
	{
		require_once SOURCE_EXT_PATH . 'common/ModelLib.class.php';
		$model = new E_lotus_grade();
		$sql = "update $this->tableName set ";
		foreach ( $model as $key => $value )
		{
			if (isset ( $info->$key ))
			{
				$sql .= "`" . $key . "`='" . $info->$key . "',";
			}
		}
		$sql = substr ( $sql, 0, - 1 );
		$sql .= " where `GradeId` = $gradeId limit 1";
		return mysql_query ( $sql );
	}
	
	public function getList()
	{
		$sql = "select * from $this->tableName order by Sort asc";
		$result = mysql_query ( $sql );
		$info = array ();
		while ( $row = mysql_fetch_assoc ( $result ) )
		{
			$info [] = $row;
		}
		return $info;
	}
	public function delByGradeId($gradeId){
		
	$sql = "delete from $this->tableName where GradeId=$gradeId limit 1";
        return mysql_query($sql);
	}
}